<template>
  <div class="app-container">
    <el-steps :active="active" finish-status="success" align-center>
      <el-step title="合同基本信息"></el-step>
      <el-step title="甲乙双方信息"></el-step>
      <el-step title="合同成员信息"></el-step>
    </el-steps>

    <el-form ref="form" :model="form" :rules="rules" label-width="180px">

      <el-row v-show="active == 1">
        <el-col :span="10">
          <div class="grid-content bg-purple">
            <el-form-item label="合同编号" prop="contractNumber">
              系统生成
            </el-form-item>
            <el-form-item style="width: 400px" label="合同名称" prop="contractName">
              <el-input v-model="form.contractName" placeholder="请输入合同名称"/>
            </el-form-item>
            <el-form-item style="width: 400px" label="负责人" prop="responsibleName">
              <el-input v-model="form.responsibleName" placeholder="请输入负责人"/>
            </el-form-item>
            <el-form-item style="width: 400px" label="负责人邮箱" prop="responsibleEmail">
              <el-input v-model="form.responsibleEmail" placeholder="请输入负责人邮箱"/>
            </el-form-item>
            <el-form-item style="width: 400px" label="经办人" prop="agentName">
              <el-input v-model="form.agentName" placeholder="请输入经办人"/>
            </el-form-item>
            <el-form-item style="width: 400px" label="经办人邮箱" prop="agentEmail">
              <el-input v-model="form.agentEmail" placeholder="请输入经办人邮箱"/>
            </el-form-item>
            <el-form-item label="合同类别" prop="category">
              <el-select v-model="form.category" placeholder="请选择合同类别">
                <el-option
                  v-for="dict in dict.type.village_contract_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="签订日期" prop="signingDate">
              <el-date-picker clearable
                              v-model="form.signingDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择签订日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="合同有效状态" prop="validityStatus">
              <el-radio-group v-model="form.validityStatus">
                <el-radio
                  v-for="dict in dict.type.village_whether"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="支付方式" prop="paymentMethod">
              <el-radio-group v-model="form.paymentMethod">
                <el-radio
                  v-for="dict in dict.type.village_payment_method"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="乙方是否盖章" prop="isCounterpartySealed">
              <el-radio-group v-model="form.isCounterpartySealed">
                <el-radio
                  v-for="dict in dict.type.village_whether"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="4" style="height: 616px;display: flex;justify-content: center">
          <div style="height: 100%;width: 2px;background-color: #d9d9d9"></div>
        </el-col>
        <el-col :span="10">
          <div class="grid-content bg-purple-light" style="margin-left: -100px">

            <el-form-item label="负责人类型" prop="responsibleType">
              <el-radio-group v-model="form.responsibleType">
                <el-radio
                  v-for="dict in dict.type.village_responsible_type"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="负责人电话" prop="phone" style="width: 400px">
              <el-input v-model="form.phone" placeholder="请输入负责人电话"/>
            </el-form-item>
            <el-form-item label="所属单位" prop="unit">
              <el-select v-model="form.unit" placeholder="请选择所属单位">
                <el-option
                  v-for="dict in dict.type.village_unit"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="经费" prop="funds" style="width: 50%">
              <el-input v-model="form.funds" placeholder="请输入经费" style="width: 200px">
                <div slot="append">万元</div>
              </el-input>
            </el-form-item>
            <el-form-item label="甲方是否盖章" prop="isFirstpartySealed">
              <el-radio-group v-model="form.isFirstpartySealed">
                <el-radio
                  v-for="dict in dict.type.village_whether"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="终止日期" prop="terminationTime">
              <el-date-picker clearable
                              v-model="form.terminationTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择终止日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="开始日期" prop="commencedTime">
              <el-date-picker clearable
                              v-model="form.commencedTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择开始日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="进行状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in dict.type.village_running_status"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="盖章页电子版" prop="electronicRecords">
              <file-upload v-model="form.electronicRecords"/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row v-show="active == 2">
        <el-col :span="10">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>甲方信息</span>
            </div>
            <div class="text item">
              <el-form ref="firstForm" :model="first" :rules="firstrules" label-width="120px">
                <el-form-item style="width: 400px" label="甲方名称" v-show="false" prop="name">
                  <el-input v-model="first.firstSecondType=1"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="甲方名称" prop="name">
                  <el-input v-model="first.name" placeholder="请输入客户名称"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="电话" prop="tel">
                  <el-input v-model="first.tel" placeholder="请输入电话"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="省份" prop="province">
                  <el-input v-model="first.province" placeholder="请输入省份"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="城市" prop="city">
                  <el-input v-model="first.city" placeholder="请输入城市"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="公司地址" prop="addr">
                  <el-input v-model="first.addr" placeholder="请输入公司地址"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="邮编" prop="postcode">
                  <el-input v-model="first.postcode" placeholder="请输入邮编"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="公司类型" prop="type">
                  <el-select v-model="first.type" placeholder="请选择公司类型">
                    <el-option
                      v-for="dict in dict.type.village_enterprise_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="parseInt(dict.value)"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item style="width: 500px" label="备注" prop="remark">
                  <el-input v-model="first.remark" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
        </el-col>
        <el-col :span="4" style="height: 570px;display: flex;justify-content: center">
          <div style="height: 100%;width: 2px;background-color: #d9d9d9"></div>
        </el-col>
        <el-col :span="10">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>乙方信息</span>
            </div>
            <div class="text item">
              <el-form ref="customerForm" :model="second" :rules="secondrules" label-width="120px">
                <el-form-item style="width: 400px" label="甲方名称" v-show="false" prop="name">
                  <el-input v-model="second.firstSecondType=2"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="客户名称" prop="name">
                  <el-input v-model="second.name" placeholder="请输入客户名称"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="电话" prop="tel">
                  <el-input v-model="second.tel" placeholder="请输入电话"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="省份" prop="province">
                  <el-input v-model="second.province" placeholder="请输入省份"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="城市" prop="city">
                  <el-input v-model="second.city" placeholder="请输入城市"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="公司地址" prop="addr">
                  <el-input v-model="second.addr" placeholder="请输入公司地址"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="邮编" prop="postcode">
                  <el-input v-model="second.postcode" placeholder="请输入邮编"/>
                </el-form-item>
                <el-form-item style="width: 400px" label="公司类型" prop="type">
                  <el-select v-model="second.type" placeholder="请选择公司类型">
                    <el-option
                      v-for="dict in dict.type.village_enterprise_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="parseInt(dict.value)"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item style="width: 500px" label="备注" prop="remark">
                  <el-input v-model="second.remark" type="textarea" placeholder="请输入内容"/>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
        </el-col>
      </el-row>


      <el-row v-show="active == 3">
        <div style="margin-bottom: 20px;text-align: right;">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
        <el-col :span="10">
          <el-form-item style="width: 500px" label="合同编号" prop="contractNumber">
            系统生成
          </el-form-item>
          <el-form-item style="width: 500px" label="合同名称" prop="contractName">
            <el-input v-model="form.contractName" placeholder="请输入合同名称"/>
          </el-form-item>
          <el-form-item style="width: 500px" label="负责人" prop="responsibleName">
            <el-input v-model="form.responsibleName" placeholder="请输入负责人"/>
          </el-form-item>


        </el-col>
        <el-col :span="4" style="height: 150px;display: flex;justify-content: center">
          <div style="height: 100%;width: 2px;background-color: #d9d9d9"></div>
        </el-col>
        <el-col :span="10">
          <el-form-item style="width: 500px" label="经办人" prop="agentName">
            <el-input v-model="form.agentName" placeholder="请输入经办人"/>
          </el-form-item>

          <el-form-item label="所属单位" prop="unit">
            <el-select v-model="form.unit" placeholder="请选择所属单位">
              <el-option
                v-for="dict in dict.type.village_unit"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="经费" prop="funds" style="width: 400px">
            <el-input v-model="form.funds" placeholder="请输入经费">
              <div slot="append">万元</div>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <div v-show="active == 3">
        <el-divider content-position="center">合同成员信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddVillageMember">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteVillageMember">删除
            </el-button>
          </el-col>
        </el-row>
        <el-table :data="villageMemberList" :row-class-name="rowVillageMemberIndex"
                  @selection-change="handleVillageMemberSelectionChange" ref="villageMember" style="width: 2000px"
        >
          <el-table-column type="selection" width="50" align="center"/>
          <el-table-column label="序号" align="center" prop="index" width="200"/>
          <el-table-column label="成员类型" align="center" prop="memberType" width="200">
            <template slot-scope="scope">
              <el-select v-model="scope.row.memberType" placeholder="请选择成员类型">
                <el-option
                  v-for="dict in dict.type.village_responsible_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="成员名称" prop="name" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.name" placeholder="请输入成员名称"/>
            </template>
          </el-table-column>
          <el-table-column align="center" label="工号" prop="jobNumber" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jobNumber" placeholder="请输入工号"/>
            </template>
          </el-table-column>
          <el-table-column align="center" label="工作单位" prop="workUnit" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.workUnit" placeholder="请输入工作单位"/>
            </template>
          </el-table-column>
          <el-table-column align="center" label="职称" prop="position" width="200">
            <template slot-scope="scope">
              <el-select v-model="scope.row.position" placeholder="请选择职称">
                <el-option
                  v-for="dict in dict.type.village_responsible_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="学位" prop="degree" width="200">
            <template slot-scope="scope">
              <el-select v-model="scope.row.degree" placeholder="请选择学位">
                <el-option
                  v-for="dict in dict.type.village_degree"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="承担类型" prop="assumeType" width="200">
            <template slot-scope="scope">
              <el-select v-model="scope.row.assumeType" placeholder="请选择承担类型">
                <el-option
                  v-for="dict in dict.type.village_assume_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="备注" prop="remark" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" placeholder="请输入备注"/>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-form>


    <div style="display: flex;justify-content: space-evenly">
      <el-button style="margin-top: 12px;width: 200px" type="primary" plain @click="lastStep" :disabled="active === 1">
        上一步
      </el-button>
      <el-button style="margin-top: 12px;width: 200px" type="primary" plain @click="next" :disabled="active === 3">
        下一步
      </el-button>
    </div>


  </div>
</template>

<script>
import { listContracts, getContracts, delContracts, addContracts, updateContracts } from '@/api/village/contracts'

export default {
  name: 'Contracts',
  dicts: ['village_enterprise_type', 'village_contract_type', 'village_payment_method', 'village_assume_type', 'village_unit', 'village_running_status', 'village_degree', 'village_whether', 'village_responsible_type'],
  data() {
    return {

      customerForm: {},
      firstForm: {},
      first: {},
      second: {},
      active: 1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedVillageMember: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合同信息管理表格数据
      contractsList: [],
      // 合同成员表格数据
      villageMemberList: [],
      villageSaleCustomerList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeSigningDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractNumber: null,
        contractName: null,
        category: null,
        signingDate: null,
        unit: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        contractName: [
          { required: true, message: '合同名称不能为空', trigger: 'blur' }
        ],
        responsibleName: [
          { required: true, message: '负责人不能为空', trigger: 'blur' }
        ],
        responsibleEmail: [
          { required: true, message: '负责人邮箱不能为空', trigger: 'blur' },
          {
            pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
            message: '请输入有效的邮箱地址',
            trigger: 'blur'
          }
        ],
        agentName: [
          { required: true, message: '经办人不能为空', trigger: 'blur' }
        ],
        agentEmail: [
          { required: true, message: '经办人邮箱不能为空', trigger: 'blur' },
          {
            pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
            message: '请输入有效的邮箱地址',
            trigger: 'blur'
          }
        ],
        category: [
          { required: true, message: '合同类别不能为空', trigger: 'change' }
        ],
        signingDate: [
          { required: true, message: '签订日期不能为空', trigger: 'blur' }
        ],
        validityStatus: [
          { required: true, message: '合同有效状态不能为空', trigger: 'change' }
        ],
        paymentMethod: [
          { required: true, message: '支付方式不能为空', trigger: 'change' }
        ],
        isCounterpartySealed: [
          { required: true, message: '乙方是否盖章不能为空', trigger: 'change' }
        ],
        responsibleType: [
          { required: true, message: '负责人类型不能为空', trigger: 'change' }
        ],
        phone: [
          { required: true, message: '负责人电话不能为空', trigger: 'blur' },
          {
            pattern: /^1[3-9]\d{9}|^(\+\d{1,4})?[-\s]?(\(?\d{1,4}\)?[-\s]?)?\d{1,4}[-\s]?\d{1,4}([-\s]?\d{1,9})?$/,
            message: '请输入正确的电话号码（支持手机号和座机）',
            trigger: 'blur'
          }
        ],
        unit: [
          { required: true, message: '所属单位不能为空', trigger: 'change' }
        ],
        funds: [
          { required: true, message: '经费不能为空', trigger: 'blur' },
          {
            pattern: /^\d+(\.\d{1,3})?$/,
            message: '经费应为最多三位小数的数字',
            trigger: 'blur'
          }
        ],
        isFirstpartySealed: [
          { required: true, message: '甲方是否盖章不能为空', trigger: 'change' }
        ],
        terminationTime: [
          { required: true, message: '终止日期不能为空', trigger: 'blur' }
        ],
        commencedTime: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '进行状态不能为空', trigger: 'change' }
        ],
        memberType: [
          { required: true, message: '成员类型不能为空', trigger: 'change' }
        ],
        name: [
          { required: true, message: '成员名称不能为空', trigger: 'blur' }
        ],
        electronicRecords: [
          { required: true, message: '成员名称不能为空', trigger: 'blur' }
        ]

      },
      customerrules: {},
      firstrules: {
        name: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        tel: [
          { required: true, message: '负责人电话不能为空', trigger: 'blur' },
          {
            pattern: /^1[3-9]\d{9}|^(\+\d{1,4})?[-\s]?(\(?\d{1,4}\)?[-\s]?)?\d{1,4}[-\s]?\d{1,4}([-\s]?\d{1,9})?$/,
            message: '请输入正确的电话号码（支持手机号和座机）',
            trigger: 'blur'
          }
        ],
        addr: [
          { required: true, message: '公司地址不能为空', trigger: 'blur' }
        ]

      },
      secondrules: {
        name: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        tel: [
          { required: true, message: '负责人电话不能为空', trigger: 'blur' },
          {
            pattern: /^1[3-9]\d{9}|^(\+\d{1,4})?[-\s]?(\(?\d{1,4}\)?[-\s]?)?\d{1,4}[-\s]?\d{1,4}([-\s]?\d{1,9})?$/,
            message: '请输入正确的电话号码（支持手机号和座机）',
            trigger: 'blur'
          }
        ],
        addr: [
          { required: true, message: '公司地址不能为空', trigger: 'blur' }
        ]

      }
    }
  },
  created() {
    this.getList()
    if (this.$route.query.type !== null) {

      if (this.$route.query.id != null) {
        this.handleUpdate(this.$route.query)
      }
    } else {

      this.reset()
    }

  },
  methods: {
    next() {
      if (this.active++ > 2) this.active = 1
    },
    lastStep() {
      if (this.active-- < 0) this.active = 3
    },
    /** 查询合同信息管理列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.daterangeSigningDate && '' != this.daterangeSigningDate) {
        this.queryParams.params['beginSigningDate'] = this.daterangeSigningDate[0]
        this.queryParams.params['endSigningDate'] = this.daterangeSigningDate[1]
      }
      listContracts(this.queryParams).then(response => {
        this.contractsList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
      this.$router.push('/contract/contracts')
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractNumber: null,
        contractName: null,
        responsibleName: null,
        responsibleEmail: null,
        agentName: null,
        agentEmail: null,
        category: null,
        signingDate: null,
        validityStatus: null,
        paymentMethod: null,
        isCounterpartySealed: null,
        responsibleType: null,
        phone: null,
        unit: null,
        funds: null,
        isFirstpartySealed: null,
        terminationTime: null,
        commencedTime: null,
        status: null,
        createdTime: null,
        updatedTime: null,
        createdBy: null,
        updatedBy: null,
        electronicRecords: null
      }
      this.villageMemberList = []
      this.villageSaleCustomerList = []
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSigningDate = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加合同信息管理'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getContracts(id).then(response => {
        this.form = response.data
        this.villageMemberList = response.data.villageMemberList
        this.villageSaleCustomerList = response.data.villageSaleCustomerList
        this.open = true
        this.title = '修改合同信息管理'
        this.villageSaleCustomerList.forEach((item, index) => {

          if (item.firstSecondType === 1) {
            this.first = item

          } else {
            this.second = item
          }
        })

      })
    },
    /** 提交按钮 */
    submitForm() {
      let valid1=false
      let valid2=false
      this.$refs['customerForm'].validate(valid => {
        if (valid) {
          valid1 = true
        }
      })
      this.$refs['firstForm'].validate(valid => {
        if (valid) {
          valid2 = true
        }
      })

      this.$refs['form'].validate(valid => {
        if (valid && valid1 && valid2) {

          this.villageSaleCustomerList.push(this.first)
          this.villageSaleCustomerList.push(this.second)
          this.form.villageSaleCustomerList = this.villageSaleCustomerList
          this.form.villageMemberList = this.villageMemberList
          if (this.form.id != null) {
            updateContracts(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
              this.form = null
              this.first = null
              this.second = null
              this.active = 1
              this.$router.push('/contract/contracts')
            })
          } else {
            addContracts(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
              this.form = null
              this.first = null
              this.second = null
              this.active = 1
              this.$router.push('/contract/contracts')
            })
          }
        }else {
          this.$modal.msgError('必要数据未填写')
        }

      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除合同信息管理编号为"' + ids + '"的数据项？').then(function() {
        return delContracts(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 合同成员序号 */
    rowVillageMemberIndex({ row, rowIndex }) {
      row.index = rowIndex + 1
    },
    /** 合同成员添加按钮操作 */
    handleAddVillageMember() {
      let obj = {}
      obj.memberType = ''
      obj.name = ''
      obj.jobNumber = ''
      obj.workUnit = ''
      obj.position = ''
      obj.degree = ''
      obj.assumeType = ''
      this.villageMemberList.push(obj)
    },
    /** 合同成员删除按钮操作 */
    handleDeleteVillageMember() {
      if (this.checkedVillageMember.length == 0) {
        this.$modal.msgError('请先选择要删除的合同成员数据')
      } else {
        const villageMemberList = this.villageMemberList
        const checkedVillageMember = this.checkedVillageMember
        this.villageMemberList = villageMemberList.filter(function(item) {
          return checkedVillageMember.indexOf(item.index) == -1
        })
      }
    },
    /** 复选框选中数据 */
    handleVillageMemberSelectionChange(selection) {
      this.checkedVillageMember = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('village/contracts/export', {
        ...this.queryParams
      }, `contracts_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>
@media (max-width: 900px) {
  .el-input {
    width: 150px;
  }
}

@media (max-width: 500px) {
  .el-input {
    width: 20px;
  }
}
</style>
